package com.zhidian.edm.controller;

import com.zhidian.edm.param.AddUserParam;
import com.zhidian.edm.param.UpdateUserParam;
import com.zhidian.edm.result.ResultResponse;
import com.zhidian.edm.service.ISysUserService;
import com.zhidian.edm.util.BeanConvertUtil;
import com.zhidian.edm.vo.SysUserVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sl
 * @since 2025-09-18
 */
@RestController
@RequestMapping("/user")
@Tag(name = "获取用户信息", description = "获取用户信息")
public class SysUserController {

    @Resource
    private ISysUserService sysUserService;

    @GetMapping("/list")
    @Operation(summary = "获取用户列表", description = "获取用户列表")
    public ResultResponse<List<SysUserVO>> getUserList(){
        return ResultResponse.success(sysUserService.getUserList());
    }

    @PostMapping("/add")
    @Operation(summary = "添加用户", description = "添加用户")
    public ResultResponse<Void> addUser(@RequestBody AddUserParam addUserParam){
        sysUserService.addUser(addUserParam);
        return ResultResponse.success();
    }

    @PutMapping("/update")
    @Operation(summary = "更新用户", description = "更新用户")
    public ResultResponse<Void> updateUser(@RequestBody UpdateUserParam updateUserParam){
        sysUserService.updateUser(updateUserParam);
        return ResultResponse.success();
    }

    @GetMapping("/{userId}")
    @Operation(summary = "获取用户信息", description = "获取用户信息")
    public ResultResponse<SysUserVO> getUserById(@PathVariable Long userId){
        return ResultResponse.success(sysUserService.getUserById(userId));
    }

}
